<?php
/**
 * Created by : PhpStorm
 * User: Shane
 * Date: 2023-05-23
 * Time: 16:27
 */
namespace app\api\controller\client;

use app\common\controller\Api;
use app\common\library\Token;

class Member extends Api
{
    /**
     * 微信授权登录
     */
    public function wxLogin(){
        $validate = new \think\Validate([
            ['code', 'require', 'code不能为空'],
            ['avatar', 'require', '头像不能为空'],
            ['nickname', 'require', '昵称不能为空'],
        ]);
        if (!$validate->check(input())) {
            $this->error('提交失败：' . $validate->getError());
        }
        $code = $this->request->param("code");
        $result = getOpenid($code);
        if (!isset($result['openid'])) {
            $this->error('请求错误', $result);
        }
        $data = [
            "nickname"     => $this->request->param("nickname"),
            "avatar"       => $this->request->param("avatar"),
            "openid"       => $result['openid'],
            "session_key"  => $result['session_key'],
            "createtime"   => time(),
        ];
        $ret = $this->auth->memberLogin($data);
        if ($ret) {
            $user=$this->auth->getUserinfo();
            $this->success("登录成功", $user);
        } else {
            $this->error($this->auth->getError());
        }
        $this->success("成功",$user);
    }

    /**
     * 短信验证码登录
     */
    public function smsLogin(){

    }

    /**
     * 我的卡劵
     */
    public function myCard(){

    }
    /**
     * 我的洗车记录
     */
    public function carWashRecord(){

    }
    /**
     * 我的消息
     */
    public function myMessages(){

    }
}